﻿#!/usr/bin/env python3

import socket
import sys

def main():
    '''echo udp server -'''
    print(main.__doc__)
    print("="*30)

    HOST = 'localhost'                 # Symbolic name meaning all available interfaces
    PORT = 1000              # Arbitrary non-privileged port
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
        s.bind((HOST, PORT))
        s.settimeout(10)
        i = 1
        while i:
            i = i-1
            print("waiting to receive msg")
            data, addr = s.recvfrom(4096)
            print("received %s bytes from %s" % (len(data), addr))
            print(data)
            if data:
                sent = s.sendto(data, addr)
                print("sent %s bytes back to %s" % (sent, addr))


if __name__=='__main__':
    main()
